package Recursive;

import java.util.Arrays;

public class MinGong {
    public static void main(String[] args) {
       int[][] i = method(8,7);
        i[3][1]=1;
        i[3][2]=1;
        i[4][3]=1;
        i[4][4]=1;

        System.out.println("前：");
        view(i);
        setWay(i,1,1);
        System.out.println("后：");
        view(i);
        }
        //行走路线下右上左
        public static boolean setWay(int[][] i,int x,int y){
                if(i[6][5]==2){//找到了
                    return true;
                }else{
                    //判断此路是否可行
                    if(i[x][y]==0){
                        i[x][y]=2;
                        if(setWay(i,x+1,y)){
                            return true;
                        }else if(setWay(i,x,y+1)){
                            return true;
                        }
                        else if(setWay(i,x-1,y)){
                            return true;
                        }
                        else if(setWay(i,x,y-1)){
                            return true;
                        }else{
                            i[x][y]=3;
                            return false;
                        }
                    }else{
                        return false;
                    }
                }
        }
    public static int[][] method(int x,int y){
        int[][] i = new int[x][y];
        for (int j = 0; j < x; j++) {
            i[j][0]=1;
            i[j][y-1]=1;
        }
        for (int j = 0; j < y; j++) {
            i[0][j]=1;
            i[x-1][j]=1;
        }
        return i;
    }
    //查看数组
    public static void view(int[][] i){
        for (int[] x : i) {
            for (int y:x) {
                System.out.print(y);
            }
            System.out.println();
        }
    }
    ////查看数组
    public static void view(int[] i){
        for (int x : i) {
            System.out.print(x);
        }
        System.out.println();
    }
}
